package com.itic.mall.mobile.statis;

import java.util.HashMap;
import java.util.Map;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import com.itic.appbase.framework.utils.NumberStringHelper;
import com.itic.appbase.framework.utils.StringHelper;
import com.itic.mall.mobile.base.BaseMobileInterface;


/**
 * 友惠家商城中心接口类
 * @author 许小宝
 * 2017年07月25日  14时11分
 */
@Controller
@RequestMapping(value="/mobile/statis")
public class MallStatisInterface
     extends BaseMobileInterface {
	
    @RequestMapping(value="/newyear")
    @ResponseBody
    public Map<String,Object> newyear(HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		String initNewYear = "0";
    		String newYear = sysSettingService.getByKey("NEW_YEAR_STATIS");
    		if( StringHelper.isNotBlank(newYear) ){
    			initNewYear=newYear;
    		}
    		initNewYear = NumberStringHelper.addString(initNewYear, "1");
    		sysSettingService.editByKey("NEW_YEAR_STATIS",initNewYear);
    		
    		resultMap.put(DATA, initNewYear);
    		
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	//log(e);
        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
    		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
    
    
    @RequestMapping(value="/newyear2")
    @ResponseBody
    public Map<String,Object> newyear2(HttpServletRequest request,HttpServletResponse response ){
    	Map<String, Object> resultMap = new HashMap<String,Object>();
    	String result = FAIL;
    	String errorCode = PARAM_ERROR_CODE;
    	String errorMsg = PARAM_ERROR_MSG;
    	try{
    		String initNewYear = "0";
    		String newYear = sysSettingService.getByKey("NEW_YEAR_2_STATIS");
    		if( StringHelper.isNotBlank(newYear) ){
    			initNewYear=newYear;
    		}
    		initNewYear = NumberStringHelper.addString(initNewYear, "1");
    		sysSettingService.editByKey("NEW_YEAR_2_STATIS",initNewYear);
    		
    		resultMap.put(DATA, initNewYear);
    		
			result = SUCCESS;
			errorCode = SUCCESS_ERROR_CODE;
        	errorMsg = SUCCESS_ERROR_MSG;  	
        	
    	}catch(Exception e){
    		errorCode = SERVER_ERROR_CODE;
        	errorMsg = SERVER_ERROR_MSG;
        	//log(e);
        	logException("MallProductInterface", "index", e.toString(),"折扣商城中心商品列表",e);
    		
    	}
    	resultMap.put(RESULT, result);
    	resultMap.put(ERROR_CODE, errorCode);
    	resultMap.put(ERROR_MSG, errorMsg);
    	isCrrossDomain(response);
    	return resultMap;
    }
}